<?php



namespace App\Http\Requests\ApiV2;

use App\Http\Requests\Backend\BaseRequest;
use Illuminate\Support\Facades\Auth;

class UploadRequest extends BaseRequest
{
    public function rules()
    {
        return [
        //    'file' => 'required|mimes:zip,pdf,jpeg,jpg,gif,png,md,doc,txt,csv,xlsx,xls,xlsm',
        ];
    }

    public function messages()
    {
        return [
            'file.required' => __('请上传文件'),
     //       'file.mimes' => __('请上传:format格式文件', ['format' => 'zip,pdf,jpeg,jpg,gif,png,md,doc,txt,csv']),
        ];
    }

    public function filldata()
    {

        $user = Auth::user();
        $url='';
        $path='';
        if ($this->hasFile('file')) {
            $file = $this->file('file');
            $size = $file->getSize();
            $disk = config('zesow.upload.attach.course.disk');
            $prefix = '/'.date("Ymd");
            $path = $this->file('file')->store(config('zesow.upload.attach.course.path') . $prefix, ['disk' => $disk]);
            $data['extension'] = $file->getClientOriginalExtension();
            $data['size'] = $size;
            $data['title'] =pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME).".".$file->getClientOriginalExtension();
            $data['disk'] = config('zesow.upload.attach.course.disk');
            $url = url(\Illuminate\Support\Facades\Storage::disk($disk)->url($path));
        }

        $data['company_id']=$user['login_company_id'];
        $data['url'] = $url;
        $data['user_id']= Auth::id();
        $data['path'] = $path;
        $data['category_id'] = (int) $this->input('category_id',0);

        return $data;
    }
}
